package com.drinks.yiniang.io.api;

import com.alibaba.fastjson.JSON;
import com.drinks.yiniang.entity.comment.CommentJson;
import com.drinks.yiniang.entity.comment.CommentSubmitJson;
import com.drinks.yiniang.entity.comment.MyCommentsJson;
import com.drinks.yiniang.entity.common.IdNameListJson;
import com.drinks.yiniang.entity.common.StringJson;
import com.drinks.yiniang.entity.community.CommunityActJson;
import com.drinks.yiniang.entity.community.CommunityDetailJson;
import com.drinks.yiniang.entity.community.CommunityHotJson;
import com.drinks.yiniang.entity.community.CommunityNewsJson;
import com.drinks.yiniang.entity.community.CommunityTopicJson;
import com.drinks.yiniang.entity.community.UserCommunityNewsJson;
import com.drinks.yiniang.io.http.HttpUrls;
import com.drinks.yiniang.utils.SharedPreUtils;
import com.hansen.library.Constants;
import com.hansen.library.entity.BaseJson;
import com.hansen.library.io.tuple.Tuple2;
import com.hansen.library.listener.APIRequestCallback;
import com.hansen.library.utils.LogUtils;

/**
 * 社区api
 * Created by han on 2019/3/6 0006.
 */

public class CommunityApiIO extends BaseApiIO {
    volatile static CommunityApiIO instance;

    static public CommunityApiIO getInstance() {
        if (instance == null) {
            synchronized (CommunityApiIO.class) {
                if (instance == null) {
                    instance = new CommunityApiIO();
                }
            }
        }
        return instance;
    }

    /**
     * 发布社区动态
     *
     * @param title    标题
     * @param content  内容
     * @param status   状态 1发布 0草稿
     * @param goodsId  商品信息（最多五个）
     * @param imgId    图片信息
     * @param topic    话题，以|分开
     * @param brandId  关联的厂商品牌ID （一个）
     * @param callback
     */
    public void doCommunityPublish(String title, String content, String status, String goodsId, String imgId,
                                   String topic, String brandId, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("title", title);
        paramsMap.put("content", content);
        paramsMap.put("status", status);
        paramsMap.put("goods_ids", goodsId);
        paramsMap.put("images_ids", imgId);
        paramsMap.put("topic", topic);
        paramsMap.put("brand_id", brandId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_PUBLISH_COMMUNITY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("发布社区动态===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 我的社区动态
     *
     * @param callback
     */
    public void getMyCommunityNew(int page, final APIRequestCallback<CommunityNewsJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_MY_COMMUNITY_NEWS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("我的社区动态===onSuccess");

                CommunityNewsJson mDataJson = JSON.parseObject(res, CommunityNewsJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 我关注的社区动态
     *
     * @param callback
     */
    public void getMyFollowCommunityNew(int page, final APIRequestCallback<CommunityNewsJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_MY_FOLLOW_COMMUNITY_NEWS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("我关注的社区动态===onSuccess");

                CommunityNewsJson mDataJson = JSON.parseObject(res, CommunityNewsJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 热门社区动态
     *
     * @param callback
     */
    public void getHotCommunityNew(int page, final APIRequestCallback<CommunityHotJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("fans_id", SharedPreUtils.getInstance().getUserID());
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_HOT_COMMUNITY_NEWS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("热门社区动态===onSuccess");

                CommunityHotJson mDataJson = JSON.parseObject(res, CommunityHotJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 社区活动动态
     *
     * @param callback
     */
    public void getCommunityActivityNew(int page, final APIRequestCallback<CommunityActJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("current_fans_id", SharedPreUtils.getInstance().getUserID());
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_ACTIVITY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区活动动态===onSuccess");

                CommunityActJson mDataJson = JSON.parseObject(res, CommunityActJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 社区详情
     *
     * @param communityId 社区动态id
     * @param callback
     */
    public void getCommunityDetail(String communityId, final APIRequestCallback<CommunityDetailJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("community_id", communityId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_DETAILS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区详情===onSuccess");

                CommunityDetailJson mDataJson = JSON.parseObject(res, CommunityDetailJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 社区点赞、取消点赞
     *
     * @param communityId 社区动态id
     * @param callback
     */
    public void doCommunityLike(String communityId, final APIRequestCallback<StringJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("community_id", communityId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_LIKE, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区点赞、取消点赞===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 社区收藏、取消收藏
     *
     * @param communityId 社区动态id
     * @param callback
     */
    public void doCommunityCollect(String communityId, final APIRequestCallback<StringJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("community_id", communityId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_COLLECT, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区收藏、取消收藏===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 社区拉黑用户或取消拉黑
     *
     * @param userId   被拉黑或取消拉黑的用户id
     * @param callback
     */
    public void doCommunityBlack(String userId, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("flag_fans_id", userId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_ADD_BLACKOR_CANCEL, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区收藏、取消收藏===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 社区活动收藏(点赞)、取消收藏(取消点赞)
     *
     * @param type     类型 0点赞（默认） 1收藏
     * @param actId    社区活动id
     * @param callback
     */
    public void doCommunityActCollectOrLike(String type, String actId, final APIRequestCallback<StringJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("type", type);
        paramsMap.put("activities_id", actId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_ACT_COLLECT_OR_LIKE, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区收藏、取消收藏===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 社区关注用户
     *
     * @param userId   关注的用户id
     * @param callback
     */
    public void doCommunityFollow(String userId, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("focus_fans_id", userId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_FOLLOW_OTHER, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区关注用户===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 社区取消关注用户
     *
     * @param userId   被取消关注的用户id
     * @param callback
     */
    public void doCommunityFollowCancel(String userId, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("focus_fans_id", userId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_FOLLOW_CANCEL, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区取消关注用户===onSuccess");

                StringJson mDataJson = JSON.parseObject(res, StringJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 我的点评列表
     *
     * @param callback
     */
    public void getMyCommunityComments(int page, final APIRequestCallback<MyCommentsJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_MY_COMMUNITY_COMMENTS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("我的点评列表===onSuccess");

                MyCommentsJson mDataJson = JSON.parseObject(res, MyCommentsJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 获取话题列表
     *
     * @param name     关键词(搜索传值)
     * @param callback
     */
    public void getCommunityTopicList(String name, final APIRequestCallback<CommunityTopicJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("name", name);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_TOPIC_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取话题列表===onSuccess");

                CommunityTopicJson mDataJson = JSON.parseObject(res, CommunityTopicJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 获取社区厂商列表
     *
     * @param name     关键词(搜索传值)
     * @param callback
     */
    public void getCommunityMfrsList(String name, final APIRequestCallback<CommunityTopicJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("name", name);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_MFRS_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取社区厂商列表===onSuccess");

                CommunityTopicJson mDataJson = JSON.parseObject(res, CommunityTopicJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }


    //-------------------------------------其他用户相关api

    /**
     * 获取其他用户的动态信息
     *
     * @param otherUserId 查看的用户id
     * @param callback
     */
    public void getOtherUserCommunityInfo(String otherUserId, final APIRequestCallback<UserCommunityNewsJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("current_fans_id", SharedPreUtils.getInstance().getUserID()); // 当前用户id, 未登录状态不传
        paramsMap.put("view_fans_id", otherUserId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_OTHER_USER_NEWS, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取其他用户的动态信息===onSuccess");

                UserCommunityNewsJson mDataJson = JSON.parseObject(res, UserCommunityNewsJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 其他用户的点评列表
     *
     * @param otherUserId 查看的用户id
     * @param callback
     */
    public void getOtherCommunityComments(String otherUserId, int page, final APIRequestCallback<MyCommentsJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("current_fans_id", SharedPreUtils.getInstance().getUserID());
        paramsMap.put("view_fans_id", otherUserId);
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_OTHER_COMMENTS_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("其他用户的点评列表===onSuccess");

                MyCommentsJson mDataJson = JSON.parseObject(res, MyCommentsJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 其他用户的社区动态
     *
     * @param userId   被查看的用户id
     * @param callback
     */
    public void getOtherCommunityNews(String userId, int page, final APIRequestCallback<CommunityNewsJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("view_fans_id", userId);
        paramsMap.put("current_fans_id", SharedPreUtils.getInstance().getUserID());//当前登录用户id, 未登录不传
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_OTHER_SHARE_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("其他用户的社区动态===onSuccess");

                CommunityNewsJson mDataJson = JSON.parseObject(res, CommunityNewsJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null && mDataJson.getData().getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    //-------------------------------------------评论

    /**
     * 获取社区评论列表
     *
     * @param communityId 社区id
     * @param page
     * @param callback
     */
    public void getCommunityCommentsList(String communityId, int page, final APIRequestCallback<CommentJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("community_id", communityId);
        paramsMap.put("fans_id", SharedPreUtils.getInstance().getUserID());
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_COMMENTS_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取社区评论列表===onSuccess");

                CommentJson mDataJson = JSON.parseObject(res, CommentJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 提交社区评论
     *
     * @param communityId 社区id
     * @param content     评价内容
     * @param pid         回复的父级id
     * @param callback
     */
    public void doCommunityComments(String communityId, String content, String pid, final APIRequestCallback<CommentSubmitJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("community_id", communityId);
        paramsMap.put("content", content);
        paramsMap.put("pid", pid);

        MainApiIO.getInstance().postRequest(HttpUrls.API_PUBLISH_COMMUNITY_COMMENT, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("提交社区评论===onSuccess");

                CommentSubmitJson mDataJson = JSON.parseObject(res, CommentSubmitJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 获取社区活动评论列表
     *
     * @param actId    社区活动id
     * @param page
     * @param callback
     */
    public void getCommunityActCommentsList(String actId, int page, final APIRequestCallback<CommentJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("activities_id", actId);
        paramsMap.put("fans_id", SharedPreUtils.getInstance().getUserID());
        paramsMap.put("page", String.valueOf(page));
        paramsMap.put("per_page", Constants.PAGE_SIZE);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_ACT_COMMENTS_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("获取社区活动评论列表===onSuccess");

                CommentJson mDataJson = JSON.parseObject(res, CommentJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 提交社区活动评论
     *
     * @param actId    社区活动id
     * @param content  评价内容
     * @param pid      回复的父级id
     * @param callback
     */
    public void doCommunityActComments(String actId, String content, String pid, final APIRequestCallback<CommentSubmitJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("activities_id", actId);
        paramsMap.put("content", content);
        paramsMap.put("pid", pid);

        MainApiIO.getInstance().postRequest(HttpUrls.API_PUBLISH_COMMUNITY_ACT_COMMENT, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("提交社区活动评论===onSuccess");

                CommentSubmitJson mDataJson = JSON.parseObject(res, CommentSubmitJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    //------------------------------------------------社区举报

    /**
     * 社区举报理由
     *
     * @param callback
     */
    public void getCommunityReportReason(final APIRequestCallback<IdNameListJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_REPORT_REASON_LIST, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区举报理由===onSuccess");

                IdNameListJson mDataJson = JSON.parseObject(res, IdNameListJson.class);

                if (callback != null) {
                    if (mDataJson != null && mDataJson.getData() != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }

    /**
     * 社区举报文章
     *
     * @param communityId 文章ID
     * @param reasonId    举报原因id
     * @param callback
     */
    public void doCommunityReport(String communityId, String reasonId, final APIRequestCallback<BaseJson, Tuple2<Integer, String>> callback) {
        paramsMap.clear();
        paramsMap.put("community_id", communityId);
        paramsMap.put("inform_type", reasonId);

        MainApiIO.getInstance().postRequest(HttpUrls.API_COMMUNITY_REPOR_COMMUNITY, paramsMap, new APIRequestCallback<String, Tuple2<Integer, String>>() {

            @Override
            public void onSuccess(String res) {
                LogUtils.d("社区举报文章===onSuccess");

                BaseJson mDataJson = JSON.parseObject(res, BaseJson.class);

                if (callback != null) {
                    if (mDataJson != null) {
                        callback.onSuccess(mDataJson);
                    } else {
                        callback.onError(new Tuple2<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG));
                    }
                }
            }

            @Override
            public void onError(Tuple2<Integer, String> error) {
                if (callback != null) {
                    callback.onError(error);
                }
            }

            @Override
            public void onComplete() {
                if (callback != null) {
                    callback.onComplete();
                }
            }
        });
    }
}
